package org.dam.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @Author dam
 * @create 2024/1/8 15:52
 */
@Controller
@RequestMapping("/user")
public class UserController {

    /**
     * 跳转到登陆页面
     * @return
     * @throws Exception
     */
    @RequestMapping("/jumplogin")
    public String jumpLogin() throws Exception {
        return "login";
    }

    /**
     * 跳转到成功页面
     * @return
     * @throws Exception
     */
    @RequestMapping("/jumpSuccess")
    public String jumpSuccess() throws Exception {
        return "success";
    }

    /**
     * 登陆提交
     * @param session
     * @param username
     * @param pwd
     * @return
     * @throws Exception
     */
    @RequestMapping("/login")
    public String login(HttpSession session, String username, String pwd) throws Exception {
        // 向session记录用户身份信息
        System.out.println("接收前端传过来的用户名===" + username);
        // 登录成功，将用户名记录到session中
        session.setAttribute("user", username);
        return "success";
    }

    /**
     * 退出登陆
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping("logout")
    public String logout(HttpSession session) throws Exception {
        // session 过期
        session.invalidate();
        return "login";
    }
}
